package org.example.spring.controller;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.example.spring.Result.Result;
import org.example.spring.entity.DTO.LoginDTO;
import org.example.spring.entity.VO.ListVO;
import org.example.spring.entity.VO.LoginVO;
import org.example.spring.entity.Value;
import org.example.spring.service.IListService;
import org.example.spring.service.IUserService;
import org.example.spring.service.IValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@Slf4j
@Api("相关接口")
public class UserController {
    @Autowired
    IUserService iUserService;
    @Autowired
    IListService iListService;
    @Autowired
    IValueService iValueService;

    /**
     * 登录相关
     */
    @PostMapping("/login")
    public Result<LoginVO> login(@RequestBody LoginDTO loginDTO){
        LoginVO vo=iUserService.login(loginDTO);
        return Result.success(vo);
    }

    /**
     * 注册相关
     */
    @PostMapping("/register")
    public Result register(@RequestBody LoginDTO loginDTO){
        iUserService.register(loginDTO);
        return Result.success();
    }

    /**
     * 获得当前用户的聊天对照表
     */
    @GetMapping
    public Result<List<ListVO>> getList(){
       List<ListVO> list= iListService.getList();
       return Result.success(list);
    }

    /**
     * 详细内容
     */
    @GetMapping("/{otherId}")
    public Result<List<Value>> getChatting(@PathVariable Integer otherId){
        List<Value> list=iValueService.getChatting(otherId);
        return Result.success(list);
    }

}
